//
//  UIView+RectCorner.m
//  xpkc
//
//  Created by TopSageOSX on 15/1/7.
//  Copyright (c) 2015年 TopSage. All rights reserved.
//

#import "UIView+RectCorner.h"

@implementation UIView (RectCorner)

//全部
- (CGFloat)cornerRadios{
    return self.layer.cornerRadius;
}
- (void)setCornerRadios:(CGFloat)cornerRadios{
    self.layer.cornerRadius = cornerRadios;
}
//单边
- (CGFloat)cornerRadiosTop{
    return self.layer.mask.cornerRadius;
}
- (void)setCornerRadiosTop:(CGFloat)cornerRadiosTop{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(cornerRadiosTop, cornerRadiosTop)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}

- (CGFloat)cornerRadiosBottom{
    return self.layer.cornerRadius;
}
- (void)setCornerRadiosBottom:(CGFloat)cornerRadiosBottom{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight) cornerRadii:CGSizeMake(cornerRadiosBottom, cornerRadiosBottom)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}

- (CGFloat)cornerRadiosLeft{
    return self.layer.cornerRadius;
}
- (void)setCornerRadiosLeft:(CGFloat)cornerRadiosLeft{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerBottomLeft) cornerRadii:CGSizeMake(cornerRadiosLeft, cornerRadiosLeft)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}

- (CGFloat)cornerRadiosRight{
    return self.layer.cornerRadius;
}
- (void)setCornerRadiosRight:(CGFloat)cornerRadiosRight{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:(UIRectCornerTopRight|UIRectCornerBottomRight) cornerRadii:CGSizeMake(cornerRadiosRight, cornerRadiosRight)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}
//单角
- (CGFloat)cornerRadiosTopLeft{
    return self.layer.cornerRadius;
}
- (void)setCornerRadiosTopLeft:(CGFloat)cornerRadiosTopLeft{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(cornerRadiosTopLeft, cornerRadiosTopLeft)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}

- (CGFloat)cornerRadiosTopRight{
    return self.layer.cornerRadius;
}
- (void)setCornerRadiosTopRight:(CGFloat)cornerRadiosTopRight{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopRight cornerRadii:CGSizeMake(cornerRadiosTopRight, cornerRadiosTopRight)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}

- (CGFloat)cornerRadiosBottomLeft{
    return self.layer.cornerRadius;
}
- (void)setCornerRadiosBottomLeft:(CGFloat)cornerRadiosBottomLeft{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerBottomLeft cornerRadii:CGSizeMake(cornerRadiosBottomLeft, cornerRadiosBottomLeft)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}
- (CGFloat)cornerRadiosBottomRight{
    return self.layer.cornerRadius;
}
- (void)setCornerRadiosBottomRight:(CGFloat)cornerRadiosBottomRight{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(cornerRadiosBottomRight, cornerRadiosBottomRight)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}
//除单角
- (CGFloat)cornerRadiosExceptTopLeft{
    return self.layer.cornerRadius;
}
- (void)setCornerRadiosExceptTopLeft:(CGFloat)cornerRadiosExceptTopLeft{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:(UIRectCornerTopRight|UIRectCornerBottomLeft|UIRectCornerBottomRight) cornerRadii:CGSizeMake(cornerRadiosExceptTopLeft, cornerRadiosExceptTopLeft)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}

- (CGFloat)cornerRadiosExceptTopRight{
    return self.layer.cornerRadius;
}
- (void)setCornerRadiosExceptTopRight:(CGFloat)cornerRadiosExceptTopRight{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerBottomLeft|UIRectCornerBottomRight) cornerRadii:CGSizeMake(cornerRadiosExceptTopRight, cornerRadiosExceptTopRight)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}

- (CGFloat)cornerRadiosExceptBottomLeft{
    return self.layer.cornerRadius;
}
- (void)setCornerRadiosExceptBottomLeft:(CGFloat)cornerRadiosExceptBottomLeft{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomRight) cornerRadii:CGSizeMake(cornerRadiosExceptBottomLeft, cornerRadiosExceptBottomLeft)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}

- (CGFloat)cornerRadiosExceptBottomRight{
    return self.layer.cornerRadius;
}
- (void)setCornerRadiosExceptBottomRight:(CGFloat)cornerRadiosExceptBottomRight{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomLeft) cornerRadii:CGSizeMake(cornerRadiosExceptBottomRight, cornerRadiosExceptBottomRight)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}
//对角线
- (CGFloat)cornerRadiosTopLeftToBottomRight{
    return self.layer.cornerRadius;
}
- (void)setCornerRadiosTopLeftToBottomRight:(CGFloat)cornerRadiosTopLeftToBottomRight{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerBottomRight) cornerRadii:CGSizeMake(cornerRadiosTopLeftToBottomRight, cornerRadiosTopLeftToBottomRight)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}

- (CGFloat)cornerRadiosTopRightToBottomLeft{
    return self.layer.cornerRadius;
}
- (void)setCornerRadiosTopRightToBottomLeft:(CGFloat)cornerRadiosTopRightToBottomLeft{
    UIBezierPath *maskpath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:(UIRectCornerTopRight|UIRectCornerBottomLeft) cornerRadii:CGSizeMake(cornerRadiosTopRightToBottomLeft, cornerRadiosTopRightToBottomLeft)];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
    masklayer.frame = self.bounds;
    masklayer.path = maskpath.CGPath;
    self.layer.mask = masklayer;
}
@end
